package com.imcoo.controller;

import com.imcoo.domain.User;
import com.imcoo.domain.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**users
 * Created by LeLe on 2017/6/17.
 */
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    UserRepository userRepository;

    @GetMapping(value = "/")
    public List<User> getUserList() {
        System.out.println(userRepository+" ====");
        return userRepository.findAll();
    }

    @PostMapping(value = "/")
    public User getUserList(User user) {
        return userRepository.save(user);
    }

    @GetMapping(value = "/{id}")
    public User getUser(@PathVariable Integer id) {
        return userRepository.findOne(id);
    }
}
